<?php

namespace App\Admin\Actions\Post;

use App\Model\Message;
use App\Model\Moment;
use App\Model\Withdraw;
use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class WithdrawVerfyOk extends BatchAction
{
    public $name = '已提现到微信零钱';
    public function handle(Collection $collection, Request $request)
    {
        $withdrawIds = $userIds = [];
        foreach ($collection as $model) {
            $withdrawIds[] = $model->id;
            $userIds[] = $model->user_id;
        }
        $count = count($withdrawIds);
        //修改提现状态
        $ret = Withdraw::whereIn('id', $withdrawIds)->limit($count)->update([
            'status' => Withdraw::STATUS_OK,
            'withdraw_way' => 'wechat_p'
        ]);
        // $time = date('Y年m月d日', strtotime((string)$record->created_at));
        $pushMsg = "你申请的提现已通过审核，请注意查收微信零钱！";
        $userIds = array_unique($userIds);
        Message::pushSystem($userIds, $pushMsg, '提现通知');
        Log::info(__CLASS__ . "==Ids:" . json_encode($withdrawIds) . "==Count:{$count}");
        return $this->response()->success('已成功修改提现')->refresh();
    }

    public function dialog()
    {
        $this->confirm('确认已提现到微信零钱？');
    }
}
